package com.zr.service;

import com.zr.dao.WorkerDao;
import com.zr.model.Worker;

import net.sf.json.JSONObject;

public class WorkerService {
    WorkerDao workerdao= new WorkerDao();
/**
 * 得到所有员工的集合
 * @param start
 * @param rows
 * @return
 */
    public JSONObject getAllWorker(int start,int rows){
      JSONObject jobj= new JSONObject();
   	  jobj.put("total", workerdao.getAllWorker());
   	  jobj.put("rows", workerdao.getAllWorker(start, rows));
      return jobj;
    }
/**
 * 提供删除员工的服务
 * @param wids
 * @return
 */
    public  int delWorkerByWids(String wids[]){
   	 int w=0;
   	 for (int i = 0; i < wids.length; i++) {
   	 w=	workerdao.delWorkerByWid(Integer.parseInt(wids[i]));
   	}
   	 return w;
    }
/**
 * 通过添加员工的功能
 * @param wname
 * @param wage
 * @param wsex
 * @param wphone
 * @param wadress
 * @param did
 * @param dname
 * @param work_age
 * @return
 */
    public JSONObject addworker(String wname,int wage,String wsex,String wphone,String wadress,int did,String dname,int work_age){
		   JSONObject jsobj= new JSONObject();
		   jsobj.put("wname",workerdao.addWorker(wname, wage, wsex, wphone, wadress, did, dname, work_age));
    	   return jsobj;
	}
/**
 * 提供员工修改的服务
 * @param wid
 * @param wname
 * @param wage
 * @param wsex
 * @param wphone
 * @param wadress
 * @param did
 * @param dname
 * @param work_age
 * @return
 */
    public int updateStudent(int wid,String wname,int wage,String wsex,String wphone,String wadress,int did,String dname,int work_age) {
		int temp=0;
		temp=workerdao.updateWoekerByWid(wid, wname, wage, wsex, wphone, wadress, did, dname, work_age);
    	return temp;
	}
    /**
     * 提供获取部门名称的服务
     * @param did
     * @return
     */
    public JSONObject validataDepartment(int did){
    	JSONObject jdbc =new JSONObject();
		jdbc.put("dname", workerdao.validataDepartment(did));
    	return jdbc;
    }
}
